# 2112302013

# 返回数字的迭代器：初始值为1，逐步递增1
class MyNumbers:
	def __iter__(self):
		self.a = 1
		return self
	
	def __next__(self):
		x = self.a
		self.a += 1
		return x
# 类对象
myclass = MyNumbers()
# 迭代器
myiter = iter(myclass)

print('数字迭代器：')
print(next(myiter))
print(next(myiter))
print(next(myiter))
print(next(myiter))
print(next(myiter))
print(next(myiter))
print(next(myiter))
print('END.26')

# StopIterationTry01.py

# generator.py

# 1231

# yield 生成器
# 节省内存

# yield有点像断点
# 加了yield的函数，每次执行到有yield的时候，会返回yield后面的值
# 并且函数会暂停，直到下次调用或迭代终止

# yield后面可以加多个数值（可以是任意类型），但返回的值是元组类型的。
def get():
	m = 0
	n = 2
	l = ['s', 1, 3]
	k = {1:1, 2:2}
	p = ('2', 's', 't')
	while True:
		m += 1
		yield m
		yield m,n,l,k,p

it = get()
print(next(it)) # 1
print(next(it))

print(next(it)) # 2
ret = next(it)
print(ret)
print(type(ret)) # <class 'tuple'>

